home *** CD-ROM | disk | FTP | other *** search
- // DateDiff.cmm - Display differences in dates where dates are
- // ver.2 in MM/DD/YYYY format
-
- SecondsPerDay = 60 * 60 * 24;
-
- main(argc,argv)
- {
- if ( argc != 3 ) {
- printf("\aDateDiff - display difference in dates\n");
- printf("USAGE: CEnvi DateDiff MM/DD/YY MM/DD/YY\n");
- ByeBye();
- }
-
- Time1 = GetTimeFromDateString(argv[1]);
- Time2 = GetTimeFromDateString(argv[2]);
-
- DiffTime = Time2 - Time1;
- DiffDay = DiffTime / SecondsPerDay;
- printf("Date difference is %d days\n",DiffDay);
- }
-
- GetTimeFromDateString(String)
- {
- if ( 3 != sscanf(String,"%d/%d/%d",Month,Day,Year) ) {
- printf("\aUnrecognized date \"%s\"\n",argv[1]);
- ByeBye();
- }
- if ( Year < 1000 ) {
- Year += ( Year < 20 ) ? 2000 : 1900 ;
- }
-
- // convert to time
- tm.tm_year = Year - 1900;
- tm.tm_mon = Month - 1;
- tm.tm_mday = Day;
- ResultTime = mktime(tm);
- if ( ResultTime < 1 ) {
- printf("%d/%d/%d is not within range of dates I can calculate.\n",
- Month,Day,Year);
- ByeBye();
- }
- return ResultTime;
- }
-
- ByeBye()
- {
- if defined(_WINDOWS_) && !defined(_SHELL_) {
- printf("press any key to exit...");
- getch();
- }
- exit(EXIT_FAILURE);
- }
-